
var table;
//相关业务逻辑
$(function(){
	page.bind();
	page.getWorkShopName();
});

var page={//页面总变量
		bind:function(){
			$("#getDcviceRealTimeBtn").bind("click",function(){
				$("#deviceRealTime").show();
				var workShopName=$("#workShopName option:selected").val();
				page.getRealTimeDevice(workShopName);
//				setInterval("table.ajax.reload( null, false)", 1000);//每秒刷新一次表格
			});
			
			$("#refers").bind("click",function(){
				table.ajax.reload( null, false);
			});
		},
		getRealTimeDevice:function(workShopName){
			table=ajaxUtil.dataTablesAjax("deviceRealTime",10,"device/getDeviceRealTime",
					{'workShopName':workShopName},[
					{"data":"status",render: function (data,type,row) {
						var str="";
						switch (data) {
			                    case "0":
			                    	str="<button class='btn btn-default radius'>断线</button>";
			                        break;
			                    case "1":
			                    	str="<button class='btn btn-warning radius'>待机</button>";
			                        break;
			                    case "2":
			                    	str="<button class='btn btn-success radius'>加工中</button>";
			                        break;
	                           }
			            return str;
			          }},
					{"data":"deviceId"},
					{"data":"factoryId"},
					{"data":"orderId"},
					{"data":"orderCount"},
					{"data":"feddingCount"},
					{"data":"procedur"},
					{"data":"alreadyProceCount",render: function (data,type,row){
						if(row.orderCount<data){
							return data+" &nbsp;<span style='color:red'>客户端未更新</span>";
						}else{
							return data;
						}
					}},
					{"data":"lastTime"}
			]);
		},
		getWorkShopName:function(){
			ajaxUtil.ajaxRuquest('weiXin/getWorkshopName',null,function(data){
				var html="";
				for(var i=0;i<data.length;i++){
					html=html+"<option value='"+data[i]+"'>"+data[i]+"</option>";
				}
				$("#workShopName").append(html);
			});
		}
}


